<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script type="text/dialog">
	$('#userAddForm').validate({
		errorElement: 'div',
		errorClass: 'help-block',
		focusInvalid: false,
		rules: {
			username:{
				required: true,
				remote:{
					url:"${pageContext.request.contextPath}/sys/user/checkUserName.do",
					data:{
						username : function(){return $("#username").val();}
					}
				}
			},
			password:{
				required:true
			},
			realname:{
				required:true
			},
			mobile:{
				phone:true
			}
		},
		messages:{
			username: {remote: "用户名已存在."}
		},
		highlight: function (e) {
			$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
		},
		success: function (e) {
			$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
			$(e).remove();
		},submitHandler: function(form) {  
              $(form).ajaxSubmit({
					beforeSubmit: showRequest,
					success:       showResponse
			});  
        },  
		errorPlacement: function(error, element) {
			if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
		}
	});

function showRequest(formData, jqForm, options){
 	var queryString = $.param(formData);
 	art.dialog({id:'uploadDialog',title:'正在处理...',content:'<img src="../resources/admin/assets/images/loading2.gif">&nbsp;&nbsp;处理中，请稍后...',width:'250px',height:'120px',lock:true,background:'#ccc'});
 	return true;
 }
 function showResponse(data){
 	art.dialog.list['uploadDialog'].close();
 	<%--var data = eval('(' + data + ')');--%>
 	if(data.success){
 		$(".error-text").html("");
		art.dialog({id:'userAddDialog'}).close();
		art.dialog({content:data.msg,resize:true,time:2,icon:'succeed',ok:function(){this.close()}});
		$('#UserTable').DataTable().draw() ;		//重新刷新数据表格
 	}else{
 		$(".error-text").html(data.msg);
		return;
 	}
 }
</script>
<div class="scheduleBox">
	<h3 class="lighter block green">编辑管理员</h3>
	<form class="form-horizontal" role= "form" id="userAddForm" name="userAddForm" method="post" action="${pageContext.request.contextPath}/sys/user/userAdd.do">
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 账号: </label>
			<div class="col-sm-8">
				<input type="text" id="username" class="col-sm-6" name="username"/>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 密码: </label>
			<div class="col-sm-8 ">
				<input type="text"  class="col-sm-6"  name="password"/>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 姓名: </label>
			<div class="col-sm-8 ">
				<input type="text"  class="col-sm-6" id="realname" name="realname"/>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 手机号码: </label>
			<div class="col-sm-8 ">
				<input type="text"  class="col-sm-6" id="mobile" name="mobile" />
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 人员备注: </label>
			<div class="col-sm-8 ">
				<input type="text"  class="col-sm-12" id="remarks" name="remarks"/>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 所属角色: </label>
			<div class="col-sm-9 ">
				<c:forEach var="roleList" items="${roleList}">
					<label>
						<input name="roleIds" type="checkbox" class="ace" value="${roleList.id}" />
						<span class="lbl"> ${roleList.rolename}</span>
					</label>
				</c:forEach>
			</div>
		</div>
		
		<div class="form-group">
			<div class="col-sm-4">
				<button type="submit" class="btn btn-sm btn-success">
				保存
				<i class="ace-icon fa fa-pencil bigger-110"></i>
				</button>
			</div>
		</div>
		
	</form>
</div>